package kr.hyunist.androidcomplete01saeildamil.ch13;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.TimePicker.OnTimeChangedListener;

public class TimePickerTest extends Activity {
	TimePicker mTime;
	TextView mTxtTime;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.timepickertest);
		
		mTime = (TimePicker) findViewById(R.id.timePickertesttp);
		mTxtTime = (TextView) findViewById(R.id.timePickertesttv);
		mTime.setOnTimeChangedListener(new OnTimeChangedListener() {
			
			@Override
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				mTxtTime.setText(String.format("%d:%d", hourOfDay, minute));
			}
			
		});
		
		//24시간제 토글
		findViewById(R.id.timePickertestbtn1).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mTime.setIs24HourView(!mTime.is24HourView());
			}
			
		});
		
		//선택기로부터 시간 조사
		findViewById(R.id.timePickertestbtn2).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String result = String.format("%d시 %d분", mTime.getCurrentHour(), mTime.getCurrentMinute());
				Toast.makeText(TimePickerTest.this, result, Toast.LENGTH_SHORT).show();
			}
			
		});
	}
}
